optee-teec: refactor plugin support#296
Conversation
903257d to
4a48066
Compare
| "init", | ||
| "invoke", |
There was a problem hiding this comment.
I see why we're avoiding macros, but using strings for function names is a bit weird.
Since most users don't need custom names anyway, how about using defaults like plugin_init and plugin_invoke? Then the default constructor only requires the name and UUID. This would clean up the API and eliminate potential typos in build.rs.
We can also provide one more constructor that accepts the customized fn name if you'd like to.
There was a problem hiding this comment.
I have restored optee-teec-macros and am considering using macros to generate the injected functions automatically. What do you think about this approach?
With this solution, developers would apply macros to their init and invoke functions:
// lib.rs
#[derive_raw_plugin_init]
fn init() -> optee_teec::Result<()> {
Ok(())
}
#[derive_raw_plugin_invoke]
fn invoke(_: &mut optee_teec::PluginParameters) -> optee_teec::Result<()> {
Ok(())
}
// build.rs
fn main() -> anyhow::Result<()> {
Config::new(Uuid::parse_str(proto::PLUGIN_UUID)?)
.with_name("syslog")
.build()?;
Ok(())
}If they need to customize the generated raw function name, it could work like this:
// lib.rs
#[derive_raw_plugin_init(raw_name = "raw_func_name")]
fn init() -> optee_teec::Result<()> {
Ok(())
}
#[derive_raw_plugin_invoke]
fn invoke(_: &mut optee_teec::PluginParameters) -> optee_teec::Result<()> {
Ok(())
}
// build.rs
fn main() -> anyhow::Result<()> {
Config::new(Uuid::parse_str(proto::PLUGIN_UUID)?)
.with_name("syslog")
.with_init_fn_name("raw_func_name")
.build()?;
Ok(())
}f93188d to
2808bfb
Compare
* Introduce optee-teec-plugin-bindgen crate to generate plugin bindings for plugin developers, replacing `plugin-static.rs` file. * Refactor optee-teec::PluginParameters and add additional methods. * Update optee-teec-sys::PluginMethod to latest version. * optee-teec-macros: rename `plugin_init` to `derive_raw_plugin_init`, and rename `plugin_invoke` to `derive_raw_plugin_invoke`.
2808bfb to
22137c5
Compare
optee-teec-plugin-bindgencrate to generate plugin bindings for plugin developers, replacingoptee-teec-macros.optee-teec::PluginParametersand add additional methods.optee-teec-sys::PluginMethodto latest version.With these changes, plugin development now only requires adding
optee-teec-plugin-bindgenas a build dependency and including the generated artifact inlib.rs.Why not use a proc macro?
I have thought about implementing a
declare_supp_pluginmacro like thisdemo:Developers can use it like:
The main issue is that developers may provide the UUID through a variable. Due to the limitations of proc macros, we cannot resolve the value of that variable during macro expansion. As a result, the UUID would need to be parsed and converted at runtime.
However, this introduces another problem: what happens if UUID parsing fails? Triggering a panic in a shared library is not a good idea and should be avoided.